package com.jinke.api.modules.base.service.impl;

import com.jinke.api.modules.app.enums.ChannelPlatform;
import com.jinke.api.modules.base.service.BaseShipService;
import com.jinke.api.modules.base.service.ThirdService;
import com.jinke.api.modules.app.util.MathUtil;
import com.jinke.api.modules.third.carryship.service.CarryShipService;
import com.jinke.api.modules.third.dqpost.service.DqpostService;
import com.jinke.api.modules.third.easypost.service.EasyPostService;
import com.jinke.api.modules.third.ezeeship.service.EzeeShipService;
import com.jinke.api.modules.third.sjgj.service.SjgjService;
import com.jinke.api.modules.ums.model.Channel;
import com.jinke.api.modules.ums.service.UmsAdminService;
import com.jinke.api.modules.ums.vo.UserChannelVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author macro
 * @since 2024-01-13
 */
@Service
@Slf4j
public class ThirdServiceImpl implements ThirdService {

    @Autowired
    private UmsAdminService umsAdminService;


    /**
     *
     * @param userId 用户
     * @param userChannelVO 下单的具体渠道
     * @param rate 运费
     * @return
     */
    @Override
    public BigDecimal calcRate(Integer userId, UserChannelVO userChannelVO, BigDecimal rate) {
        Channel channel = userChannelVO.getChannel();
        //获取个人利润费率
        BigDecimal addRate = umsAdminService.getRate(userId);
        //依渠道整体溢价
        BigDecimal channelPrice = rate.multiply(addRate).multiply(channel.getRate()).add(channel.getPrice());
        //依个人授权渠道溢价
        return MathUtil.formatBigDecimal(channelPrice.multiply(userChannelVO.getRate()).add(userChannelVO.getPrice()));
    }

    /**
     * 计算加成后的保费
     *
     * @param rate
     * @return
     */
    @Override
    public BigDecimal calcInsurance(BigDecimal rate) {
        BigDecimal ratio=new BigDecimal(0.11);
        return MathUtil.formatBigDecimal(rate.multiply(ratio));
    }


}
